package com.zzy.web;

import com.zhuozhengsoft.pageoffice.FileSaver;
import com.zhuozhengsoft.pageoffice.OpenModeType;
import com.zhuozhengsoft.pageoffice.PageOfficeCtrl;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 上传文件的插件
 * @author zzy
 *
 */
public class TestServlet extends HttpServlet {


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        res.setContentType("text/html; charset=UTF-8");
        PrintWriter out = res.getWriter();
       /* String t = req.getParameter("t");
        if(t!=null && t.equals("open")){

        }else{

        }*/

        test1(req,res);
        out.flush();
        out.close();

    }


    public void test1(HttpServletRequest request, HttpServletResponse response){
        PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);//获取pageoffice对象
        poCtrl1.setServerPage("poserver.zz"); //此行必须
        // Create custom toolbar
        //poCtrl1.addCustomToolButton("保存", "SaveDocuments()", 1);//SaveDocuments与jsp页面中的js函数名字一致,数字代表的是对应的图标
        poCtrl1.addCustomToolButton("-", "", 0);
        poCtrl1.addCustomToolButton("打印", "ShowPrintDlg()", 6);
        poCtrl1.addCustomToolButton("-", "", 0);
        poCtrl1.addCustomToolButton("全屏切换", "SetFullScreen()", 4);
        poCtrl1.addCustomToolButton("-", "", 0);
        //poCtrl1.addCustomToolButton("加盖印章", "AddSeal()", 5);
        //poCtrl1.addCustomToolButton("手写签批", "AddHandSign()", 5);
        //poCtrl1.addCustomToolButton("验证印章", "VerifySeal()", 5);
        poCtrl1.setSaveFilePage("test2");//保存需要执行的的action
        //poCtrl1.webOpen("doc/test.docx", OpenModeType.docNormalEdit, "张三");//需要打开的打开的文档

        poCtrl1.webOpen("doc/test.docx", OpenModeType.docReadOnly, "张三");//需要打开的打开的文档 //只读的word

        poCtrl1.setTagId("PageOfficeCtrl1"); //此行必须和前端中的<po:PageOfficeCtrl id="PageOfficeCtrl1" />id保持一致







        try{
            //response.sendRedirect("editfile.jsp");
            request.getRequestDispatcher("editfile.jsp").forward(request, response);//转发
        }catch (Exception e){
            e.printStackTrace();
        }

    }

}
